package com.zhkj.txg.module.mine.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.entity.CouponListEntity
import java.math.BigDecimal

class CouponAdapter :
    BaseQuickAdapter<CouponListEntity, BaseViewHolder>(R.layout.item_coupon), LoadMoreModule {

    var showButton = false
        set(value) {
            if (field != value) {
                field = value
                notifyDataSetChanged()
            }
        }

    init {
        addChildClickViewIds(R.id.viewCoupon, R.id.tvCouponJump)
    }

    override fun convert(helper: BaseViewHolder, item: CouponListEntity) {

        helper.setText(R.id.tvCouponPrice, SpanUtil.setMoneySymbol(item.money, false))
            .setText(R.id.tvCouponName, item.name)
            .setText(
                R.id.tvCouponLimit,
                if (item.condition != "0") context.getString(
                    R.string.condition_format,
                    BigDecimal(item.condition)
                ) else context.getString(R.string.condition_non)
            )
            .setText(R.id.tvCouponValidity, "${item.startTime} - ${item.endTime}")
//            .setGone(R.id.tvCouponJump, !showButton)
        when (item.status) {
            "1" -> {
                helper.setImageResource(R.id.ivCoupon, R.drawable.bg_coupon_used)
                    .setVisible(R.id.ivCouponLabel, true)
                    .setImageResource(R.id.ivCouponLabel, R.drawable.ic_coupon_label_used)
            }
            "2" -> {
                helper.setImageResource(R.id.ivCoupon, R.drawable.bg_coupon_expired)
                    .setVisible(R.id.ivCouponLabel, true)
                    .setImageResource(R.id.ivCouponLabel, R.drawable.ic_coupon_label_expired)
            }
            else -> {
                helper.setImageResource(R.id.ivCoupon, R.drawable.bg_coupon_use)
                    .setVisible(R.id.ivCouponLabel, false)
            }
        }
    }
}